<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Classify extends Model
{
    protected $table = 'classify';
    public $timestamps = false;
    protected $guarded = [
      ];


    public function getData($search = [], $page = 1, $length = 20){
        $classifyList = array();
        $classifyList['pageData'] = array();
        $date = date('Y-m-d H:i:s', time());

        $sql = \DB::table($this->table)
            ->whereNull('deleted_at');

        if(isset($search['classname'])){
            $sql->where('classname','like' ,"%".$search['classname']."%");
        }

        $classifyList['pageData']['count']     = $sql->count();
        $classifyList['pageData']['lastPage']  = ceil($classifyList['pageData']['count'] / $length);

        $classifyList['list'] = $sql->orderBy('sort', 'asc')
            ->skip(($page-1) * $length)->take($length)
            ->get();


        return $classifyList;
    }
    //添加
    public function saveData($data){
        return \DB::table($this->table)->insert($data);
    }
    //修改
    public function saveEdit($data,$id){
        return \DB::table($this->table)->where('id',$id)->update($data);
    }
    //删除
    public function Del($data,$id){
        return \DB::table($this->table)->where('id',$id)->update($data);
    }
}